//
//  BBTextFieldViewModel.m
//  BBKit
//
//  Created by apple on 2019/6/28.
//  Copyright © 2019年 baobao. All rights reserved.
//

#import "BBTextFieldViewModel.h"
#import "UIControl+Event.h"

#define BBKIT_SETPRAGRA_TEXTFIELD_API(methodName, paraType)    BBKIT_SETPRAGRA_API(methodName,paraType, UITextField, BBTextFieldViewModel*)

@implementation BBTextFieldViewModel

BBKIT_SETPRAGRA_TEXTFIELD_API(text, NSString *);
BBKIT_SETPRAGRA_TEXTFIELD_API(attributedText, NSAttributedString *);

BBKIT_SETPRAGRA_TEXTFIELD_API(font, UIFont *);
BBKIT_SETPRAGRA_TEXTFIELD_API(textColor, UIColor *);

BBKIT_SETPRAGRA_TEXTFIELD_API(textAlignment, NSTextAlignment);
BBKIT_SETPRAGRA_TEXTFIELD_API(borderStyle, UITextBorderStyle);

BBKIT_SETPRAGRA_TEXTFIELD_API(defaultTextAttributes, NSDictionary *);

BBKIT_SETPRAGRA_TEXTFIELD_API(placeholder, NSString *);
BBKIT_SETPRAGRA_TEXTFIELD_API(attributedPlaceholder, NSAttributedString *);

BBKIT_SETPRAGRA_TEXTFIELD_API(keyboardType, UIKeyboardType);

BBKIT_SETPRAGRA_TEXTFIELD_API(clearsOnBeginEditing, BOOL);
BBKIT_SETPRAGRA_TEXTFIELD_API(adjustsFontSizeToFitWidth, BOOL);
BBKIT_SETPRAGRA_TEXTFIELD_API(minimumFontSize, CGFloat);

BBKIT_SETPRAGRA_TEXTFIELD_API(delegate, id<UITextFieldDelegate>);

BBKIT_SETPRAGRA_TEXTFIELD_API(background, UIImage *);
BBKIT_SETPRAGRA_TEXTFIELD_API(disabledBackground, UIImage *);

BBKIT_SETPRAGRA_TEXTFIELD_API(allowsEditingTextAttributes, BOOL);
BBKIT_SETPRAGRA_TEXTFIELD_API(typingAttributes, NSDictionary *);

BBKIT_SETPRAGRA_TEXTFIELD_API(clearButtonMode, UITextFieldViewMode);
BBKIT_SETPRAGRA_TEXTFIELD_API(leftView, UIView *);
BBKIT_SETPRAGRA_TEXTFIELD_API(leftViewMode, UITextFieldViewMode);
BBKIT_SETPRAGRA_TEXTFIELD_API(rightView, UIView *);
BBKIT_SETPRAGRA_TEXTFIELD_API(rightViewMode, UITextFieldViewMode);

BBKIT_SETPRAGRA_TEXTFIELD_API(inputView, UIView *);
BBKIT_SETPRAGRA_TEXTFIELD_API(inputAccessoryView, UIView *);

//BBKIT_SETPRAGRA_TEXTFIELD_API(enabled, BOOL);

- (BBTextFieldViewModel* (^)(BOOL enable))enabled{
    return ^(BOOL enable){
        ((UITextField *)self.view).enabled = enable;
        return  self;
    };
}

- (BBTextFieldViewModel *(^)(UIControlEvents controlEvents, void (^eventBlock)(id sender)))eventBlock
{
    return ^BBTextFieldViewModel *(UIControlEvents controlEvents, void (^eventBlock)(id sender)) {
        [(UIControl *)self.view addControlEvents:controlEvents handler:eventBlock];
        return self;
    };
}
@end
